package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.common.service.exception.GuiguException;
import com.atguigu.spzx.manager.service.BrandServcie;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product/brand")
@Tag(name = "品牌管理模块")
public class BrandController {
    @Autowired
    private BrandServcie brandServcie;

    @GetMapping("/{page}/{limit}")
    @Operation(summary = "查询品牌分页信息")
    public Result<PageInfo<Brand>> GetBrandPage(@PathVariable Integer page,
                                           @PathVariable Integer limit){
     PageInfo<Brand> info=brandServcie.findAllByPage(page,limit);
     return Result.build(info, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("save")
    @Operation(summary = "增加品牌")
    public  Result save(@RequestBody Brand brand){
        brandServcie.addBrand(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("保存成功");
    }
    @PutMapping("updateById")
    @Operation(summary = "保存品牌")
    public  Result updateById(@RequestBody Brand brand){
        brandServcie.updateById(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }

    @GetMapping("getById/{id}")
    @Operation(summary = "根据id查询品牌信息")
    public Result<Brand> getById(@PathVariable Long id){
       Brand brand= brandServcie.getById(id);
        return Result.build(brand,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("deleteById/{id}")
    @Operation(summary = "根据id删除品牌信息")
    public Result deleteById(@PathVariable Long id){
        brandServcie.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }

    @GetMapping("findAll")
    @Operation(summary = "查询所有的品牌数据")
    public Result<List<Brand>> findAll(){
        List<Brand> list =brandServcie.findAll();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }
}
